#!/usr/bin/env python
""" This application requires sqlite3 and the sqlite3 app. Pictures must
    be placed in a directory called 'img' with no subdirectories.

    There are two different functions:
    1. Battle Mode
        Battle mode is a head-to-head contest where you choose one picture
        over another. The winning picture gets an improved rating, and the
        losing picture gets a lower rating.
    2. Browse Mode
        Browse mode allows you to view the pictures in order of ranking,
        from highest to lowest. Left and right arrow keys will allow you
        to move forward and backward in the series.
"""

import cherrypy as web,sys,os
from libs import server # the webserver library

port = 8080

try:
  port = int(sys.argv[1])
except:
  pass

title = "Picture Battle!" # This is the title of the website
prompt = "Pick the picture you like most!<br>You can also vote using the '1' and '2' keys!" # This will tell the user what to do

# This configuration allows for static images from the img directory
conf = {
  '/':
    { 'tools.staticdir.root': os.path.dirname(os.path.abspath(__file__))},
    '/img': {
      'tools.staticdir.on': True,
      'tools.staticdir.dir': 'img/'
    },
    'global':{
      'server.environment':'production',
      'server.socket_host':'0.0.0.0',
      'server.socket_port':port,
    }
  }

web.quickstart(server.WebServer(title,prompt),config=conf) # start the webserver attached to our database